package com.atguigu.controller;


import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.entity.PlatformPropertyValue;
import com.atguigu.result.RetVal;
import com.atguigu.service.PlatformPropertyKeyService;
import com.atguigu.service.PlatformPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性表 前端控制器
 * </p>
 *
 * @author zhangqiang
 * @since 2021-08-21
 */
@RestController
@RequestMapping("/product")
//@CrossOrigin
public class PlatformPropertyController {
    @Autowired
    private PlatformPropertyKeyService propertyKeyService;
    @Autowired
    private PlatformPropertyValueService propertyValueService;

    //http://10.211.55.97/product/getPlatformPropertyByCategoryId/2/13/61
    //1.根据分类查询有哪些平台属性
    @GetMapping("getPlatformPropertyByCategoryId/{category1Id}/{category2Id}/{category3Id}")
    public RetVal getPlatformPropertyByCategoryId(@PathVariable Long category1Id,
                                                  @PathVariable Long category2Id,
                                                  @PathVariable Long category3Id){
       List<PlatformPropertyKey> platformPropertyKeyList= propertyKeyService.getPlatformPropertyByCategoryId(category1Id,category2Id,category3Id);
       return RetVal.ok(platformPropertyKeyList);
    }

    //product/getPropertyValueByPropertyKeyId/4
    //2.根据平台属性key的id得到平台属性值
    @GetMapping("getPropertyValueByPropertyKeyId/{propertyKeyId}")
    public RetVal getPropertyValueByPropertyKeyId(@PathVariable Long propertyKeyId){
        List<PlatformPropertyValue> propertyValueList = propertyValueService.getPropertyValueByPropertyKeyId(propertyKeyId);
        return RetVal.ok(propertyValueList);
    }

    //http://10.211.55.98/product/savePlatformProperty
    //3.保存平台属性
    @PostMapping("savePlatformProperty")
    public RetVal savePlatformProperty(@RequestBody PlatformPropertyKey platformPropertyKey){
        propertyKeyService.savePlatformProperty(platformPropertyKey);
        return RetVal.ok();
    }

    //4.根据skuId查询平台属性信息
    @GetMapping("getPlatformPropertyBySkuId/{skuId}")
    public List<PlatformPropertyKey> getPlatformPropertyBySkuId(@PathVariable Long skuId){
        return propertyKeyService.getPlatformPropertyBySkuId(skuId);
    }
}

